home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / APW.SC / SC07Jiffy.Wind / Jiffy.asm1 < prev    next >
Encoding:
Text File  |  1990-06-24  |  37.7 KB  |  941 lines  |  [TEXT/pdos]

  1. *******************************************************************************
  2. *
  3. * Jiffy Windows - Pixel Transfer Demonstration
  4. *
  5. * (C)  Copyright Apple Computer, Inc. 1988-1990
  6. * All rights reserved.
  7. *
  8. * Developer Technical Support Apple II Sample Code
  9. *
  10. * by Keith Rollin
  11. *
  12. * This program shows the use of PPToPort and OffScreen GrafPorts in
  13. * the implementation of a window content caching system. It presents 5 "Test"
  14. * windows and a large window full of text to show the effects of this caching.
  15. *
  16. * Caching is setup at the time the window is created and performed the first
  17. * time the window needs to be updated (drawn). Before the window is created,
  18. * a routine (AddCacheRecord) is called to create a "Cache Record". The handle
  19. * to this cache record is stored in the window's RefCon, and contains infor-
  20. * mation on the offscreen image. When it comes time to draw to the screen, this
  21. * record is examined to see if there is any information buffered already. If
  22. * not, then drawing occurs to the offscreen buffer. After an offscreen image
  23. * has been made, updates are performed by calling PPToPort to copy the image
  24. * from the offscreen buffer to the screen. If, for any reason, an offscreen
  25. * buffer cannot be made, drawing occurs to the window directly.
  26. *
  27. * An effort has been made to make this caching as transparent as possible.
  28. * Windows act normally, and the routines that update them in a normal envi-
  29. * ronment can be used in this buffered environment. The caching routine is
  30. * inserted in between TaskMaster and the update routine, and calls the update
  31. * routine almost as if it were called by TaskMaster. The only difference is
  32. * that the routine is drawing to an offscreen GrafPort, and not a Window
  33. * record.
  34. *
  35. * A change was made to work around a bug in fastFont on system disk 5.0.  A
  36. * routine called xorPoint was added.  This takes care of the bug.
  37. *
  38. *******************************************************************************
  39.                     eject
  40.                     
  41. **********************************************************************
  42. *                                                                    *
  43. *             Apple IIGS Source Code Sampler, Volume I               *
  44. *                                                                    *
  45. *             Copyright (c) Apple Computer, Inc. 1988-1990           *
  46. *                       All Rights Reserved                          *
  47. *                                                                    *
  48. *            Written by Apple II Developer Tech Support              *
  49. *                                                                    *
  50. *                                                                    *
  51. *                                                                    *
  52. *  ----------------------------------------------------------------  *
  53. *                                                                    *
  54. *     This program and its derivatives are licensed only for         *
  55. *     use on Apple computers.                                        *
  56. *                                                                    *
  57. *     Works based on this program must contain and                   *
  58. *     conspicuously display this notice.                             *
  59. *                                                                    *
  60. *     This software is provided for your evaluation and to           *
  61. *     assist you in developing software for the Apple IIGS           *
  62. *     computer.                                                      *
  63. *                                                                    *
  64. *     DISCLAIMER OF WARRANTY                                         *
  65. *                                                                    *
  66. *     THE SOFTWARE IS PROVIDED "AS IS" WITHOUT                       *
  67. *     WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,               *
  68. *     WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS             *
  69. *     FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO             *
  70. *     THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH            *
  71. *     YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND            *
  72. *     NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)               *
  73. *     ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,             *
  74. *     REPAIR OR CORRECTION.                                          *
  75. *                                                                    *
  76. *     Apple does not warrant that the functions                      *
  77. *     contained in the Software will meet your requirements          *
  78. *     or that the operation of the Software will be                  *
  79. *     uninterrupted or error free or that defects in the             *
  80. *     Software will be corrected.                                    *
  81. *                                                                    *
  82. *     SOME STATES DO NOT ALLOW THE EXCLUSION                         *
  83. *     OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY              *
  84. *     NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC            *
  85. *     LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS                *
  86. *     WHICH VARY FROM STATE TO STATE.                                *
  87. *                                                                    *
  88. *                                                                    *
  89. **********************************************************************
  90.                     eject
  91.                     
  92.                     case   on
  93.  
  94.  
  95.                     copy 2/ainclude/E16.Quickdraw
  96.                     copy 2/ainclude/E16.Memory
  97.                     copy 2/ainclude/E16.EVENT
  98.                     copy 2/ainclude/E16.Window
  99.                     copy 2/ainclude/E16.Dialog
  100.                     mcopy macros/jiffy.macros
  101.  
  102. *******************************************************************************
  103. *
  104. *    Equates used in this program.
  105. *
  106. *******************************************************************************
  107. DPHandle            gequ 0               ; Handle to Tool Direct Page area
  108. DPPointer           gequ DPHandle+4      ; Pointer to Tool Direct Page area
  109. Deref               gequ DPPointer+4     ; Temporary Handle dereference area
  110. CPPtr               gequ Deref+4         ; pointer to current caching parms
  111. temp1               gequ CPPtr+4         ; temp pointer
  112. temp2               gequ temp1+4         ; temp pointer
  113.  
  114. ScreenMode          gequ mode640
  115. ScreenWidth         gequ 640
  116.  
  117. CacheRecordSize     gequ 12
  118.  
  119.                     EJECT
  120. *******************************************************************************
  121. *
  122. Main                start
  123. *
  124. * Description:      This is the main routine. It calls routines to Initialize
  125. *                   the tools, initialize application specific data, run the
  126. *                   main EventLoop, close the application, and close the tools.
  127. *                   Then it calls the ProDOS Quit command.
  128. *
  129. *
  130. * Inputs:           NONE
  131. *
  132. * Outputs:          NONE
  133. *
  134. * External Refs:
  135. *                   Import InitTools
  136. *                   Import InitApp
  137. *                   Import EventLoop
  138. *                   Import CloseApp
  139. *                   Import CloseTools
  140. *                   Import QuitParms
  141. *
  142. * Entry Points:     NONE
  143. *
  144. *******************************************************************************
  145.  
  146.                     jsr InitTools
  147.                     jsr InitApp
  148.  
  149.                     _ShowCursor
  150.  
  151.                     jsr EventLoop
  152.  
  153.                     jsr CloseApp
  154.                     jsr CloseTools
  155.  
  156.                     _Quit QuitParms
  157.  
  158.                     end
  159.  
  160.                     EJECT
  161. *******************************************************************************
  162. *
  163. Globals             data
  164. *
  165. * Description:      Holder of all of our data.
  166. *
  167. *
  168. * Inputs:           N/A
  169. *
  170. * Outputs:          N/A
  171. *
  172. * External Refs:
  173. *                   Import DrawOdyRtn
  174. *                   Import CacheContent
  175. *                   Import DrawContent
  176. *
  177. * Entry Points:
  178. *                   Export QuitParms    ; used by Main
  179. *
  180. *******************************************************************************
  181. *
  182. * Standard global data
  183. *
  184. *******************************************************************************
  185.  
  186. TitleString         str 'Jiffy Windows'
  187. AutString           str 'By Keith Rollin, Apple II DTS'
  188. CopyString          str 'Copyright (c) 1988-1990 Apple Computer'
  189. VerString           str 'Version 3.0        June 19, 1990'
  190. AboutData           dc c'73/*0',i1'13',c'*1',i1'13',c'*2',i1'13',c'*3/^#0',i1'0'
  191. SubStrings          dc i4'TitleString,AutString,CopyString,VerString'
  192.  
  193. MenuHeight          ds 2                ; Stored height of menu bar
  194. MyID                ds 2                ; Application ID
  195. MyDP                ds 2                ; My direct page storage
  196.  
  197. QuitFlag            ds 2
  198. QuitParms           dc i4'0'            ; Pathname of next app
  199.                     dc i2'$00'          ; flags
  200.  
  201. EventRecord         ANOP
  202. EventWhat           ds 2
  203. EventMessage        ds 4
  204. EventWhen           ds 4
  205. EventWhere          ds 4
  206. EventModifiers      ds 2
  207. TaskData            ds 4
  208. TaskMask            dc i4'$0000FFFF'
  209.  
  210.                     EJECT
  211. *******************************************************************************
  212. *
  213. * Application specific global data
  214. *
  215. *******************************************************************************
  216.  
  217. ; This is a list of pointers to the text that is used to create our menus. It
  218. ; is used by InitApp to find all of the menu templates and use them to create
  219. ; our menubar. This loop loads MenuPtrLen-4 into an index, gets the
  220. ; corresponding menu template pointer in this table, and uses that in a
  221. ; NewMenu call. It then decrements the index by 4, and repeats the procees
  222. ; until the index is negative.
  223.  
  224. MenuPtr             dc i4'AppMenu'
  225.                     dc i4'FileMenu'
  226.                     dc i4'EditMenu'
  227. MenuPtrLen          equ *-MenuPtr
  228.  
  229.  
  230. ; Menu list: menu items should be numbered consecutivly starting from 250.
  231. ; As a convention, use 256 as about and 257 as Quit.
  232.  
  233. AppMenu             dc c'$$@\XN1',h'0D'
  234.                     dc c'--About Jiffy Windows...\N256V',i1'0'
  235.                     dc c'.'
  236. FileMenu            dc c'$$  File  \N2',i1'0'
  237.                     dc c'--Open Test Windows\N258',i1'0'
  238.                     dc c'--Read a book\N259',i1'0'
  239.                     dc c'--Close\N255DV',i1'0'
  240.                     dc c'--Quit\N257*Qq',i1'0'
  241.                     dc c'.'
  242. EditMenu            dc c'$$  Edit  \N3',i1'0'
  243.                     dc c'--Undo\N250*ZzVD',i1'0'
  244.                     dc c'--Cut\N251*XxD',i1'0'
  245.                     dc c'--Copy\N252*CcD',i1'0'
  246.                     dc c'--Paste\N253*VvD',i1'0'
  247.                     dc c'--Clear\N254D',i1'0'
  248.                     dc c'.'
  249.  
  250. wPtr1               dc i4'0'
  251. wPtr2               dc i4'0'
  252. wPtr3               dc i4'0'
  253. wPtr4               dc i4'0'
  254. wPtr5               dc i4'0'
  255. OdyWindow           dc i4'0'
  256.  
  257. WindowTitle1        str '  Window 1 (not Cached)  '
  258. WindowTitle2        str '  Window 2 (not Cached)  '
  259. WindowTitle3        str '  Window 3 (Cached)  '
  260. WindowTitle4        str '  Window 4 (Cached)  '
  261. WindowTitle5        str '  Window 5 (Cached)  '
  262.  
  263. wtPtrs              dc i4'WindowTitle1,WindowTitle2'
  264.                     dc i4'WindowTitle3,WindowTitle4'
  265.                     dc i4'WindowTitle5'
  266.  
  267. Stripes             ANOP
  268.                     dc i2'$0000'        ; Black frame
  269.                     dc i2'$0f00'        ; Inact TBcolor, Inact TColor, Tcolor
  270.                     dc i2'$020f'        ; Pattern, Pattern color, BG color
  271.                     dc i2'$0000'        ; Frame growbox unselcted/selected
  272.                     dc i2'$00f0'        ; infobar color (white)
  273.  
  274. MWindData           dc i2'MWEnd-MWindData'
  275.                     dc i2'fTitle+fClose+fMove'
  276. WindowTitle         dc i4'0'            ; Ptr to title
  277.                     dc i4'0'            ; RefCon
  278.                     dc i2'0,0,0,0'      ; Full Size (0= default)
  279.                     dc i4'Stripes'      ; Color Table Pointer
  280.                     dc i2'0,0'          ; Vertical/Horizontal origin
  281.                     dc i2'0,0'          ; Data area height, width
  282.                     dc i2'0,0'          ; Max Cont height, width
  283.                     dc i2'0,0'          ; Pixels to scroll vert'ly, horiz'ly
  284.                     dc i2'0,0'          ; Pixels to page vert'ly, horiz'ly
  285.                     dc i4'0'            ; Information bar refcon.
  286.                     dc i2'0'            ; Info bar height
  287.                     dc i4'0'            ; DefProc.
  288.                     dc i4'0'            ; Routine to draw info. bar.
  289. ContDraw            dc i4'CacheContent' ; Routine to cache/draw content.
  290. wPosition           dc i2'10,40,120,400'                    ; Size and position
  291.                     dc i4'$FFFFFFFF'    ; Plane to put window up in (bottommost).
  292.                     dc i4'0'            ; Address for window record (0 to alloc)
  293. MWEnd               ANOP
  294. ;
  295. ; These parms MUST follow immediately after the window record
  296. ;
  297. MWCacheParms        dc i4'DrawContent-1'                    ; real draw routine
  298.                     dc i4'0'            ; space for caching handle
  299.                     dc i2'110,360'      ; Height, width
  300.  
  301.  
  302. OdyTitle            str '  Odyssey  '
  303. OdyWindData         dc i2'OdyEnd-OdyWindData'
  304.                     dc i2'fTitle+fClose+fMove+fRScroll+fBScroll+fGrow'
  305.                     dc i4'OdyTitle'     ; Ptr to title
  306.                     dc i4'0'            ; RefCon
  307.                     dc i2'0,0,0,0'      ; Full Size (0= default)
  308.                     dc i4'Stripes'      ; Color Table Pointer
  309.                     dc i2'0,0'          ; Vertical/Horizontal origin
  310.                     dc i2'797,600'      ; Data area height, width
  311.                     dc i2'0,0'          ; Max Cont height, width
  312.                     dc i2'32,32'        ; Pixels to scroll vert'ly, horiz'ly
  313.                     dc i2'0,0'          ; Pixels to page vert'ly, horiz'ly
  314.                     dc i4'0'            ; Information bar refcon.
  315.                     dc i2'0'            ; Info bar height
  316.                     dc i4'0'            ; DefProc.
  317.                     dc i4'0'            ; Routine to draw info. bar.
  318.                     dc i4'CacheContent' ; Routine to cache/draw content.
  319.                     dc i2'30,5,185,605' ; Size and position
  320.                     dc i4'$FFFFFFFF'    ; Plane to put window up in (bottommost).
  321.                     dc i4'0'            ; Address for window record (0 to alloc)
  322. OdyEnd              ANOP
  323. ;
  324. ; These parms MUST follow immediately after the window record
  325. ;
  326. OdyCacheParms       dc i4'DrawOdyRtn-1'
  327.                     dc i4'0'            ; space for caching handle
  328.                     dc i2'792,640'      ; Height, width
  329.  
  330. Odyssey             ANOP
  331.                     dc i1'13,13'
  332.                     dc i1'1',c'J',i1'1,0'
  333.                     dc i1'1',c'F',i1'0,0,0,16'              ; Shaston 16
  334.                     dc c'1',i1'13'
  335.                     dc c'Boot Camp',i1'13'
  336.                     dc i1'1',c'J',i1'2,0'
  337.                     dc i1'1',c'F',i1'0,0,0,8'               ; Shaston 8
  338.                     dc i1'13,13'
  339.                     dc c'      At Pepsi, we lived for the smallest details.'
  340.                     dc i1'13,13'
  341.                     dc c'     The moment I entered the boardroom, I knew the '
  342.                     dc c'meeting would be momentous.  For years, these '
  343.                     dc c'executive sessions had followed a carefully '
  344.                     dc c'orchestrated ritual.  Today, there was a subtle, '
  345.                     dc c'though telling, difference.',i1'13,13'
  346.  
  347.                     dc c'     Ordinarily, the conference table''s 21-foot-'
  348.                     dc c'long surface, polished to look more like glass than '
  349.                     dc c'the rare burl of Carpathian elm, would be touched '
  350.                     dc c'only by PepsiCo board members, and then no more '
  351.                     dc c'than twelve times a year.  Today, the fitted leather '
  352.                     dc c'covering that hid the gleaming top was removed.'
  353.                     dc i1'13,13'
  354.  
  355.                     dc c'     I had been in this room at least a hundred '
  356.                     dc c'times.  I had sat worried at this table and I had '
  357.                     dc c'nearly soared at it.  I had witnessed tense '
  358.                     dc c'colleagues - friends - being publicly hung for '
  359.                     dc c'questions of performance, and I had seen them '
  360.                     dc c'applauded, just as I had been here, for marketing '
  361.                     dc c'ideas and strategies.',i1'13,13'
  362.  
  363.                     dc c'     But this meeting was different.  The table''s '
  364.                     dc c'exposed top said so.  It made the spacious, '
  365.                     dc c'windowless room all the more imposing.  Like nearly '
  366.                     dc c'everything else at PepsiCo, Inc., the room''s '
  367.                     dc c'stately power and elegance made you stand a little '
  368.                     dc c'straighter.  A large abstact painting by Jackson '
  369.                     dc c'Pollock''s widow, Lee Krasner, dominated the far '
  370.                     dc c'wall.  Custom-designed carpeting in earth-tone '
  371.                     dc c'colors cushioned the floor.  The bronze-plated '
  372.                     dc c'ceiling, perhaps more appropriate for a church, '
  373.                     dc c'reflected burnished mahogany-paneled walls.  High-'
  374.                     dc c'backed beige leather chairs, so imposing they could '
  375.                     dc c'have carried corporate titles of their own, '
  376.                     dc c'surrounded the boardroom table.',i1'13,13'
  377.  
  378.                     dc c'     Every two months the marketing gurus of Pepsi '
  379.                     dc c'-- the company''s heart and soul -- would gather '
  380.                     dc c'here, on 4/3, the executive floor of PepsiCo''s '
  381.                     dc c'corporate headquarters in the New York City suburb '
  382.                     dc c'of Purchase, for a private ritual in the public war '
  383.                     dc c'on the colas between Pepsi and Coke.  A. C. Neilsen '
  384.                     dc c'Co., the country''s most prestigious market-'
  385.                     dc c'research firm, would formally present what became '
  386.                     dc c'popularly known as the Nielsens -- closely guarded '
  387.                     dc c'market-share figures that showed how we were faring '
  388.                     dc c'in our competitive battle with Coca-Cola Co.  The '
  389.                     dc c'Nielsens defined the ground rules of competition '
  390.                     dc c'for everyone at Pepsi.  They were at the epicenter '
  391.                     dc c'of all we did.  They were the non-public body counts '
  392.                     dc c'of the Cola Wars.',i1'13,13'
  393.  
  394.                     dc c'     Like the other meetings, this one was a '
  395.                     dc c'ceremonial event.  We marked it on our calendars '
  396.                     dc c'many weeks in advance.  Everyone wore the unofficial '
  397.                     dc c'corporate uniform: a blue pin-striped suit, white '
  398.                     dc c'shirt, and a sincere red tie.  None of us would ever '
  399.                     dc c'remove his jacket.  We dressed and acted as if we '
  400.                     dc c'were at a meeting of the board of directors.',i1'13,13'
  401.  
  402.                     dc c'     The Nielsen executives were the first to '
  403.                     dc c'arrive.  They carried themselves like accountants -- '
  404.                     dc c'good presenters with bland personalities in blue '
  405.                     dc c'and gray suits.  They were followed by Pepsi''s '
  406.                     dc c'junior executives, the support staff of market '
  407.                     dc c'researchers and brand managers who could provide a '
  408.                     dc c'stray fact or figure for the division officers and '
  409.                     dc c'vice presidents who filed into the room next.'
  410.                     dc i1'13,13'
  411.  
  412.                     dc c'     Everyone in this room was on the fast track, '
  413.                     dc c'which at Pepsi was more like a racecourse.  The '
  414.                     dc c'senior officers here were the best of the best.  In '
  415.                     dc c'a corporation populated with bright, ambitious '
  416.                     dc c'achievers, they were peerless.  They had proven they '
  417.                     dc c'were intellectually and physically fit supervisors '
  418.                     dc c'in America''s corporate Marine Corps.',i1'13,13'
  419.  
  420.                     dc c'     As president of Pepsi-Cola, I entered the room '
  421.                     dc c'next.  Corporate formality dictated where all of us '
  422.                     dc c'sat.  The company''s top officers gravitated to the '
  423.                     dc c'front of the table, the junior execs toward the '
  424.                     dc c'back.  Staff people found chairs away from the table '
  425.                     dc c'along the walls.  When everyone was in place, I went '
  426.                     dc c'across the hall to alert PepsiCo''s president, '
  427.                     dc c'Andrall E. Pearson, who then joined us.',i1'13,13'
  428.                     
  429.                     dc c'     Everyone chatted away until the heavy wooden '
  430.                     dc c'doors opened once again.  The room fell quiet as a '
  431.                     dc c'big-boned man with a frizzy shock of white hair '
  432.                     dc c'strode in.  PepsiCo chairman and chief executive '
  433.                     dc c'Donald M. Kendall, fifty-seven, was no taller than '
  434.                     dc c'six feet one, but he was a man of enormous '
  435.                     dc c'presence, respected and feared by colleagues.  '
  436.                     dc c'Today, Kendall was feeling great pleasure.  He '
  437.                     dc c'worked the room like a politician, gripping hands, '
  438.                     dc c'slapping backs, and giving an occasional bear hug '
  439.                     dc c'-- a patented gesture of strength and affection '
  440.                     dc c'that Kendall reserved for only a few.',i1'13,13'
  441.                     dc c'From Odyssey by John Sculley',i1'13'
  442.                     dc c'Used by Permission, Harper & Row, Publishers, Inc.'
  443.                     dc i1'13,13'
  444. OdysseyEnd          ANOP
  445.                     end
  446.  
  447.                     EJECT
  448. *******************************************************************************
  449. *
  450. InitApp             start
  451. *
  452. * Description:      Perform any application specific initialization.
  453. *
  454. * Inputs:           NONE
  455. *
  456. * Outputs:          NONE
  457. *
  458. * External Refs:
  459. *                   Import SlowDraw
  460. *
  461. * Entry Points:     NONE
  462. *
  463. *******************************************************************************
  464.                     using Globals
  465.  
  466.                     stz QuitFlag
  467.  
  468. ;
  469. ; Create 5 test windows. Loop from 4 to 0, calling AddWindow with
  470. ; the loop index in the accumulator. AddWindow will use this index
  471. ; to name the window, determine if it should be cached or not, and
  472. ; stagger its position.
  473. ;
  474.  
  475.                     lda #4
  476.                     sta Windex
  477. loop                lda Windex
  478.                     jsr AddWindow
  479.                     dec Windex
  480.                     bpl loop
  481.  
  482.  
  483. ;
  484. ; Create the window to hold John "The Dude" Sculley's book.
  485. ;
  486.                     lda #OdyWindData    ; create a cache record for it
  487.                     ldx #^OdyWindData
  488.                     jsr AddCacheRecord
  489.  
  490.                     pha
  491.                     pha
  492.                     PushLong #OdyWindData
  493.                     _NewWindow
  494.                     PullLong OdyWindow
  495.  
  496.                     rts
  497.  
  498. Windex              ds 2
  499.  
  500. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  501. ;
  502. ; Enter this routine with an index from 0 to 4. This index is
  503. ; used to set the window's title from a list of titles, stagger
  504. ; its position and to determine whether or not it should be cached.
  505. ;
  506.  
  507. AddWindow           ANOP
  508.  
  509. ;
  510. ; Turn the window counter into an array index. This index is
  511. ; stored in X and is used throughout the routine, so I need
  512. ; to be sure not to destroy it!
  513. ;
  514.                     asl a
  515.                     asl a
  516.                     tax
  517.                     stx IndexSave
  518. ;
  519. ; Set up the pointer to the window's name
  520. ;
  521.                     lda wtPtrs,x
  522.                     sta WindowTitle
  523.                     lda wtPtrs+2,x
  524.                     sta WindowTitle+2
  525.  
  526. ; Bump the window's position so as to stagger them
  527.  
  528.                     ldy #6
  529. loop2               lda wPosition,y
  530.                     clc
  531.                     adc #20
  532.                     sta wPosition,y
  533.                     dey
  534.                     dey
  535.                     bpl loop2
  536.  
  537. ; the last 2 windows are special...they don't get cached...
  538.  
  539.                     cpx #4
  540.                     bne CreateIt
  541.                     lda #SlowDraw
  542.                     sta ContDraw
  543.                     lda #^SlowDraw
  544.                     sta ContDraw+2
  545.  
  546. CreateIt            ANOP
  547.                     lda #MWindData      ; create a cache record for it
  548.                     ldx #^MWindData
  549.                     jsr AddCacheRecord
  550.  
  551.                     pha
  552.                     pha
  553.                     PushLong #MWindData
  554.                     _NewWindow
  555.  
  556.                     ldx IndexSave
  557.                     lda 1,s
  558.                     sta wPtr1,x         ; now save our window pointer in our
  559.                     lda 3,s             ; window pointer array.
  560.                     sta wPtr1+2,x
  561. ;
  562. ; the window pointer is still on the stack, so use it to
  563. ; set the current port (NewWindow doesn't do that!!!)
  564. ;
  565.                     _SetPort
  566.  
  567. done                ANOP
  568.                     rts
  569.  
  570. IndexSave           ds 2
  571.  
  572. ;
  573. ; Just before creating a new window, we must create a cache record for it.
  574. ; This record will hold: a) the routine to draw the contents the first time,
  575. ; b) a pointer to the offscreen GrafPort, and c) the dimensions needed to
  576. ; create the GrafPort. This cache record is created from a template stored
  577. ; IMMEDIATELY after the window parameter list (after owStorage).
  578. ;
  579. ; Enter this routine with the pointer to the window parameter list in A,X.
  580. ;
  581. AddCacheRecord      ANOP
  582.                     sta temp1
  583.                     stx temp1+2         ; temp1 now points to the parmlist
  584.  
  585.                     clc                 ; make a pointer to the template
  586.                     adc #owStorage+4
  587.                     sta temp2
  588.                     stx temp2+2
  589.  
  590.                     pha                 ; space for the new handle
  591.                     pha
  592.                     PushLong #CacheRecordSize
  593.                     PushWord MyID
  594.                     PushWord #attrNoCross
  595.                     PushLong #$0000
  596.                     _NewHandle
  597.                     PullLong myHandle   ; handle to cache record in Deref
  598.  
  599.                     PushLong temp2      ; copy the template over
  600.                     PushLong myHandle
  601.                     PushLong #CacheRecordSize
  602.                     _PtrToHand
  603.  
  604.                     ldy #owRefCon       ; set the RefCon to the handle
  605.                     lda myHandle
  606.                     sta [temp1],y
  607.                     iny
  608.                     iny
  609.                     lda myHandle+2
  610.                     sta [temp1],y
  611.  
  612.                     rts
  613.  
  614. myHandle            ds 4
  615.  
  616.                     end
  617.  
  618.                     EJECT
  619. *******************************************************************************
  620. *
  621. CloseApp            start
  622. *
  623. * Description:      Close down things. This disposes of all items and memory
  624. *                   that we allocated.
  625. *
  626. *
  627. * Inputs:           NONE
  628. *
  629. * Outputs:          NONE
  630. *
  631. * External Refs:    NONE
  632. *
  633. * Entry Points:     NONE
  634. *
  635. *******************************************************************************
  636.                     using Globals
  637.  
  638. ; Sly Trick #1!!! Traverse the window list, clearing the visible
  639. ; bit in each one. Then, when the window manager closes down, it
  640. ; will think that all windows are hidden, and it will NOT erase
  641. ; them from the screen. This makes quitting faster!
  642.  
  643.                     pha                 ; get a pointer to the first
  644.                     pha                 ; window.
  645.                     _GetFirstWindow
  646.                     PullLong temp1
  647.  
  648. loop                ANOP
  649.                     pha                 ; get the window's bit flags
  650.                     PushLong temp1
  651.                     _GetWFrame
  652.                     pla
  653.  
  654.                     and #$FFFF-fVis     ; turn off the Vis Flag
  655.  
  656.                     pha                 ; now send it back out
  657.                     PushLong temp1
  658.                     _SetWFrame
  659.  
  660.                     pha                 ; get the next window in the
  661.                     pha                 ; list
  662.                     PushLong temp1
  663.                     _GetNextWindow
  664.                     PullLong temp1
  665.  
  666.                     lda temp1           ; If NULL ($0000 0000) was returned
  667.                     bne loop            ; then we are out to windows to
  668.                     lda temp1+2         ; fix.
  669.                     bne loop
  670.  
  671.                     rts
  672.                     end
  673.  
  674.                     EJECT
  675. *******************************************************************************
  676. *
  677. EventLoop           start
  678. *
  679. * Description:      Main Event Loop. Handle things until user selects Quit.
  680. *
  681. *
  682. * Inputs:           NONE
  683. *
  684. * Outputs:          NONE
  685. *
  686. * External Refs:
  687. *                   Import MenuSelect
  688. *                   Import Ignore
  689. *                   Import doUpdate
  690. *                   Import doClose
  691. *
  692. * Entry Points:     NONE
  693. *
  694. *******************************************************************************
  695.                     using Globals
  696.  
  697.                     pha                 ; Push on space for TaskMaster result
  698.                     PushWord #everyEvent ; GetNextEvent mask
  699.                     PushLong #EventRecord ; Pointer to Event Record
  700.                     _TaskMaster
  701.  
  702.                     pla                 ; Get TaskMaster result
  703.                     beq EventLoop       ; Remove if you want to use null events
  704.                     asl A               ; Turn it into an index
  705.                     tax
  706.                     jsr (TaskTable,x)   ; Call appropriate event handler
  707.  
  708.                     lda QuitFlag        ; Quit selected?
  709.                     beq EventLoop       ; no - keep looping
  710.  
  711.                     rts                 ; yes- leave the program
  712.  
  713. TaskTable           dc i2'Ignore'       ; 0 Null
  714.                     dc i2'Ignore'       ; 1 MouseDown
  715.                     dc i2'Ignore'       ; 2 MouseUp
  716.                     dc i2'Ignore'       ; 3 KeyDown
  717.                     dc i2'Ignore'       ; 4 undefined
  718.                     dc i2'Ignore'       ; 5 AutoKey
  719.                     dc i2'Ignore'       ; 6 Update
  720.                     dc i2'Ignore'       ; 7 undefined
  721.                     dc i2'Ignore'       ; 8 Activate
  722.                     dc i2'Ignore'       ; 9 Switch
  723.                     dc i2'Ignore'       ; 10 Desk accessory
  724.                     dc i2'Ignore'       ; 11 Device driver
  725.                     dc i2'Ignore'       ; 12 ap
  726.                     dc i2'Ignore'       ; 13 ap
  727.                     dc i2'Ignore'       ; 14 ap
  728.                     dc i2'Ignore'       ; 15 ap
  729.                     dc i2'Ignore'       ; TASK 0 indesk
  730.                     dc i2'MenuSelect'   ; TASK 1 in menuBar
  731.                     dc i2'Ignore'       ; TASK 2 in system window
  732.                     dc i2'Ignore'       ; TASK 3 in content
  733.                     dc i2'Ignore'       ; TASK 4 in Drag
  734.                     dc i2'Ignore'       ; TASK 5 in grow
  735.                     dc i2'doClose'      ; TASK 6 in goaway
  736.                     dc i2'Ignore'       ; TASK 7 in zoom
  737.                     dc i2'Ignore'       ; TASK 8 in info bar
  738.                     dc i2'MenuSelect'   ; TASK 9 in special menu
  739.                     dc i2'Ignore'       ; TASK 10 in NDA
  740.                     dc i2'Ignore'       ; TASK 11 in frame
  741.                     dc i2'Ignore'       ; TASK 12 in drop
  742.  
  743.                     end
  744.  
  745.                     EJECT
  746. *******************************************************************************
  747. *
  748. MenuSelect          start
  749. *
  750. * Description:      This routine is called when TaskMaster returns a menu
  751. *                   event. It takes the menu item that was hit and calculates
  752. *                   an offset into the menu dispatch table. It then calls that
  753. *                   routine and unhilites the menu when it is done.
  754. *
  755. * Inputs:           TaskData holds menu item selected.
  756. *
  757. * Outputs:          NONE
  758. *
  759. * External Refs:
  760. *                   Import Ignore
  761. *                   Import doClose
  762. *                   Import doAbout
  763. *                   Import doQuit
  764. *                   Import doOpenTest
  765. *                   Import doShowOdy
  766. *
  767. * Entry Points:     NONE
  768. *
  769. *******************************************************************************
  770.                     using Globals
  771.  
  772.                     lda TaskData        ; Get the ID of the menu item selected.
  773.                     sec                 ; Turn it into an index by subtracting
  774.                     sbc #250            ; the starting ID number (25) and mul-
  775.                     asl a               ; tiplying by 2 (each table entry con-
  776.                     tax                 ; sists of 2 bytes).
  777.                     jsr (MenuTable,x)   ; Call the routine behind it.
  778.  
  779.                     PushWord #0         ; Routine done - unhilite the menubar.
  780.                     PushWord TaskData+2
  781.                     _HiLiteMenu
  782.  
  783.                     rts
  784.  
  785. MenuTable           dc i2'Ignore'       ; undo
  786.                     dc i2'Ignore'       ; cut
  787.                     dc i2'Ignore'       ; copy
  788.                     dc i2'Ignore'       ; paste
  789.                     dc i2'Ignore'       ; clear
  790.                     dc i2'doClose'      ; close
  791.                     dc i2'doAbout'
  792.                     dc i2'doQuit'
  793.                     dc i2'doOpenTest'   ; open 5 windows with stuff in them
  794.                     dc i2'doShowOdy'    ; purge the refcons
  795.                     end
  796.  
  797.                     EJECT
  798. *******************************************************************************
  799. *
  800. Ignore              start
  801. *
  802. * Description:      Called when I want to ignore an event.
  803. *
  804. *
  805. * Inputs:           NONE
  806. *
  807. * Outputs:          NONE
  808. *
  809. * External Refs:    NONE
  810. *
  811. * Entry Points:     NONE
  812. *
  813. *******************************************************************************
  814.  
  815.                     rts
  816.                     end
  817.  
  818.                     EJECT
  819. *******************************************************************************
  820. *
  821. doAbout             start
  822. *
  823. * Description:      Bring up an Alert Dialog box with our name in it. This
  824. *                   uses the new _AlertWindow call implemented in the Window
  825. *                   Manager on System Disk 3.2.
  826. *
  827. * Inputs:           NONE
  828. *
  829. * Outputs:          NONE
  830. *
  831. * External Refs:    NONE
  832. *
  833. * Entry Points:     NONE
  834. *
  835. *******************************************************************************
  836.                     using Globals
  837.  
  838.                     pha                 ; space for result
  839.                     PushWord #1         ; we are using P-Strings
  840.                     PushLong #SubStrings
  841.                     PushLong #AboutData
  842.                     ldx #$590E          ; _AlertWindow
  843.                     jsl $E10000
  844.                     pla                 ; pull off button hit
  845.  
  846.                     rts
  847.                     end
  848.  
  849.                     EJECT
  850. *******************************************************************************
  851. *
  852. doOpenTest          start
  853. *
  854. * Description:      Open the 5 test windows that we created in InitApp. It
  855. *                   merely loops through an array of 5 window pointers and
  856. *                   calls SelectWindow and ShowWindow for all of them. It then
  857. *                   disables the menu item that was used to call this routine
  858. *                   and enables the Close menu Item.
  859. *
  860. *
  861. * Inputs:           NONE
  862. *
  863. * Outputs:          NONE
  864. *
  865. * External Refs:    NONE
  866. *
  867. * Entry Points:     NONE
  868. *
  869. *******************************************************************************
  870.                     using Globals
  871.  
  872.                     lda #4              ; we need to count through 5 windows
  873. loop                ANOP
  874.                     pha                 ; save the counter on the stack
  875.                     asl a               ; turn it into an index
  876.                     asl a
  877.                     tax
  878.                     lda wPtr1+2,x       ; get a window pointer from my array
  879.                     tay                 ; of test windows.
  880.                     lda wPtr1,x
  881.  
  882.                     phy                 ; push on window ptr for _SelectWindow
  883.                     pha
  884.                     phy                 ; push on window ptr for _ShowWindow
  885.                     pha
  886.  
  887.                     _SelectWindow       ; Bring the window to front
  888.                     _ShowWindow         ; Make it visible
  889.  
  890.                     pla                 ; get my counter back
  891.                     dec a               ; loop down to the next window.
  892.                     bpl loop            ; if >= 0 keep looping
  893.  
  894.                     PushWord #258       ; Disable (Open Test Windows) item
  895.                     _DisableMItem
  896.  
  897.                     PushWord #255       ; windows are open, enable close item
  898.                     _EnableMItem
  899.  
  900.                     rts
  901.                     end
  902.  
  903.                     EJECT
  904. *******************************************************************************
  905. *
  906. doShowOdy           start
  907. *
  908. * Description:      Show the window that displays the first few pages of John
  909. *                   Buddy's book. This routine Selects the window, and then
  910. *                   Shows it to make it visible. It finishes up by disabling
  911. *                   the Read a Book menu item and enabling the Close item.
  912. *
  913. *
  914. * Inputs:           NONE
  915. *
  916. * Outputs:          NONE
  917. *
  918. * External Refs:    NONE
  919. *
  920. * Entry Points:     NONE
  921. *
  922. *******************************************************************************
  923.                     using Globals
  924.  
  925.                     PushLong OdyWindow
  926.                     _SelectWindow
  927.  
  928.                     PushLong OdyWindow
  929.                     _ShowWindow
  930.  
  931.                     PushWord #255       ; windows are open - enable close item
  932.                     _EnableMItem
  933.  
  934.                     PushWord #259       ; Disable (Read Book) item
  935.                     _DisableMItem
  936.  
  937.                     rts
  938.                     end
  939.  
  940.                     copy jiffy.asm2
  941.